package com.cloudcentral.config;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;
import java.util.Collections;

/**
 * Create by Administrator
 * 2023/11/10 10:18
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
@JsonIgnoreProperties(ignoreUnknown = true)
public class SMSAuthenticationToken extends AbstractAuthenticationToken {
  private final Object principal;
  private Object credentials;

  public SMSAuthenticationToken() {
    super(Collections.emptyList());
    this.principal = "";
    this.credentials = "";
    super.setAuthenticated(false);
  }

  public SMSAuthenticationToken(Object principal, Object credentials) {
    super(Collections.emptyList());
    this.principal = principal;
    this.credentials = credentials;
    super.setAuthenticated(false);
  }

  public SMSAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
    super(authorities);
    this.principal = principal;
    this.credentials = credentials;
    super.setAuthenticated(true);
  }

  @Override
  public Object getCredentials() {
    return credentials;
  }

  @Override
  public Object getPrincipal() {
    return principal;
  }

  @Override
  public void setAuthenticated(boolean authenticated) {
    //Assert.isTrue(!authenticated, "Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead");
    super.setAuthenticated(false);
  }

  @Override
  public void eraseCredentials() {
    super.eraseCredentials();
    credentials = null;
  }
}
